//
//  OAuthTool.m
//  WeiBTest
//
//  Created by Zc_zhou on 15/9/15.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "OAuthTool.h"
#define path [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:@"account.archieve"]
@implementation OAuthTool

+(void)saveAccount:(OAuthModel *)account
{
 
    [NSKeyedArchiver archiveRootObject:account toFile:path];
    
 
    
}

+(OAuthModel*)getOutAccount
{
    
    
    OAuthModel *account= [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    
    
    long long expires_in = [account.expires_in longLongValue];
    
    NSDate *expresTime = [account.created_time dateByAddingTimeInterval:expires_in];
    
    NSDate *currentData = [NSDate date];
    
    NSComparisonResult result = [expresTime compare:currentData];
    
    if (result != NSOrderedDescending) {
        return nil;
    }
    return account;
    
    
}
@end
